package functions;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.JOptionPane;


public class Server extends Thread {

	private int porta;

	public Server (int porta){
		this.porta=porta;
	}

	public void run() {
		while(true){
			try {
				ServerSocket server = new ServerSocket(porta);
				Socket s = server.accept();	
				BufferedReader entrada = new BufferedReader(new InputStreamReader(s.getInputStream()));
				String[] msg = entrada.readLine().split(";");				
				int resp=JOptionPane.showConfirmDialog(null, "Seu parceiro(a) "+msg[1]+"\n " +
						"lhe enviou um clip. Deseja Aceitar?");
				if (resp==0){
					TextTransfer.setStringToClipboard(msg[0]);
				}
				
				server.close();
				s.close();
				entrada.close();
				
			} catch (Exception e) {
				e.printStackTrace();
			}  
		}
	}	

	public int getPorta() {
		return porta;
	}

	public void setPorta(int porta) {
		this.porta = porta;
	}	
}
